//
//  PlistWriter.m
//  Version 1.0
//
//  Created by Matri Ning on 12/13/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "PlistHandle.h"

@implementation PlistHandle
 

- (NSString *)dataFilePath:(NSString *)fileName { 
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0]; 
	return [documentsDirectory stringByAppendingPathComponent:fileName];
}

-(NSMutableDictionary *)readContent {
	NSString *filePath = [self dataFilePath:filename]; 
	if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
		NSMutableDictionary *array = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
		return array;
	}else{
		return nil;
	}
	/*NSEnumerator *enumerator=[array objectEnumerator];
	id object;
	while(object=[enumerator nextObject]){
		NSLog(@"i found %@",object);
	}*/
}	  


-(void) writeContent: (NSMutableDictionary *) givenDict{

	NSMutableDictionary *dict = givenDict;
	//[dict setValue:keyContent forKey:keyName];
	[dict writeToFile:[self dataFilePath:filename] atomically:YES];
	//[dict release];
}

-(PlistHandle *) initWithName : (NSString *) n; {
	self=[super init];
	filename=n;
	return self;
}

- (void)dealloc {
    [super dealloc];
	
	NSLog(@"PlistHandle dealloc");
	
	//[self release];
}

@end
